package com.general.template.controller;

import com.general.template.enums.ResultEnum;
import com.general.template.pojo.PowerUser;
import com.general.template.service.PowerUserService;
import com.general.template.utils.Result;
import com.general.template.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 杰哥
 * Date: 2021/2/16 15:30
 * @Description:
 **/
@RequestMapping("user")
@RestController
@Api(value="用户前台",description = "用户对自身账号的查看和修改")
public class UserController {

    @Autowired
    private PowerUserService powerUserService;

    /**
     * 用户修改密码
     *
     * @author 杰哥
     * @date 2021/2/16 15:33
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="updatePwd",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="修改密码",notes = "用户修改密码")
    public Result<Object> update(@RequestBody UserVo user){
        int pwd = this.powerUserService.updatePwd(user);
        if (pwd == 0){
            return new Result<>(ResultEnum.SUCCESS,"密码修改失败!原密码不正确");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"密码修改成功!");
        }
    }

    /**
     * 修改信息
     *
     * @author 杰哥
     * @date 2021/2/16 16:01
     * @param user
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="updateInfo",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="修改信息",notes = "用户修改信息")
    public Result<Object> updateInfo(@RequestBody PowerUser user){
        int pwd = this.powerUserService.updateUser(user);
        if (pwd == 0){
            return new Result<>(ResultEnum.SUCCESS,"信息修改失败!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"信息修改成功!");
        }
    }

}
